package com.regexp;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Author : hebad90@163.com
 * @Date : 2014/9/2 10:18
 * @From : javalearn
 */
public class Test {
    public static void main(String[] args) {
        test7();
    }

    public static void test6() {
        String str = "wdfdf";
        Pattern pattern = Pattern.compile("[a-z]+");
        Matcher matcher = pattern.matcher(str);
        System.out.println(matcher.matches());
    }

    public static void test5() {
        String str = "ceponline@yahoo.com.cn";
        Pattern pattern = Pattern.compile("[//w//.//-]+@([//w//-]+//.)+[//w//-]+", Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(str);
        System.out.println(matcher.matches());
    }

    public static void test4() {
        Pattern pattern = Pattern.compile("正则表达式");
        Matcher matcher = pattern.matcher("正则表达式 Hello World,正则表达式 Hello World ");
        StringBuffer sbr = new StringBuffer();
        while (matcher.find()) {
            matcher.appendReplacement(sbr, "Java");
        }
        matcher.appendTail(sbr);
        System.out.println(sbr.toString());
    }

    public static void test3() {
        Pattern pattern = Pattern.compile("正则表达式");
        Matcher matcher = pattern.matcher("正则表达式 Hello World,正则表达式 Hello World");
        //替换第一个符合正则的数据
        System.out.println(matcher.replaceAll("Java"));
    }

    //包含验证
    public static void test1() {
        Pattern pattern = Pattern.compile("^Java.*");
        Matcher matcher = pattern.matcher("Java不是人");
        boolean b = matcher.matches();
        //当条件满足时，将返回true，否则返回false
        System.out.println(b);
    }

    public static void test2() {
        Pattern pattern = Pattern.compile("[, |]+");
        String[] strs = pattern.split("Java Hello World  Java,Hello,,World|Sun");
        for (int i = 0; i < strs.length; i++) {
            System.out.println(strs[i]);
        }

    }

    public static void test7() {
        String s = "【淘宝】亲，本店镇店之宝现货2014秋装新款衬衣 淑女范优雅蝴蝶结纯色长袖雪纺衫 打底衫女于2014-10-30 09:41 - 2014-11-06 09:41限量大促，只有2400件！http://item.taobao.com/item.htm?id=41963538343";
        System.out.println(s.startsWith("【淘宝】"));
    }

}
